Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6907975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:30:08+00:00 2026-05-27T08:30:08+00:00

I have a link on a webpage that sends emails out from localhost SMTP

  • 0

I have a link on a webpage that sends emails out from localhost SMTP with pdf attachments created from iText that I made following How to create an in-memory PDF report and send as an email attachment using iText and Java and it is working, however when I get the emails I can’t see the sender name/address.

It shows as being from “(unknown sender)” in my gmail inbox and if I hit reply the ‘to’ box is completely blank. In hotmail is shows as being from “(Unknown)” but when i open it, the sender shows as “admin@whatever.com on behalf of (Unknown)”

When I test the SMTP on the server through telnet, the sender name I make up comes through just fine. How can I get it to show up when the application sends the email?

Here is the code that sends the email:

    String smtpHost = "localhost";
    int smtpPort = 25;
    String sender = "admin@whatever.com";
    String[] recipient = pdfEmail.replaceAll("\\ ", "").split(",");
    String content = "whatever"; 
    String subject = "whatever"; 

    Properties props = new Properties();
    props.put("mail.smtp.host", smtpHost);
    props.put("mail.smtp.user", sender);
    props.put("mail.smtp.port", smtpPort);

    Session session = Session.getDefaultInstance(props, null);

    ByteArrayOutputStream outputStream = null;

    try {          
        //construct the text body part
        MimeBodyPart textBodyPart = new MimeBodyPart();
        textBodyPart.setText(content);

        //now write the PDF content to the output stream
        outputStream = new ByteArrayOutputStream();
        writePdf(outputStream); //creates PDF
        byte[] bytes = outputStream.toByteArray();

        //construct the pdf body part
        DataSource dataSource = new ByteArrayDataSource(bytes, "application/pdf");
        MimeBodyPart pdfBodyPart = new MimeBodyPart();
        pdfBodyPart.setDataHandler(new DataHandler(dataSource));
        pdfBodyPart.setFileName("test.pdf");

        //construct the mime multi part
        MimeMultipart mimeMultipart = new MimeMultipart();
        mimeMultipart.addBodyPart(textBodyPart);
        mimeMultipart.addBodyPart(pdfBodyPart);

        //create the sender/recipient addresses
        InternetAddress iaSender = new InternetAddress(sender);     
        InternetAddress[] toAddress = new InternetAddress[recipient.length];

        // To get the array of addresses
        for( int i=0; i < recipient.length; i++ ) { 
            toAddress[i] = new InternetAddress(recipient[i]);
        }

        //construct the mime message
        MimeMessage mimeMessage = new MimeMessage(session);

        for( int i=0; i < toAddress.length; i++) { 
            mimeMessage.addRecipient(Message.RecipientType.TO, toAddress[i]);
        }

        mimeMessage.setSender(iaSender);
        mimeMessage.setSubject(subject);
        mimeMessage.setRecipients(Message.RecipientType.TO, toAddress);
        mimeMessage.setContent(mimeMultipart);

        //send off the email         
        Transport.send(mimeMessage);

    } catch(Exception ex) {
        ex.printStackTrace();
    } finally {
        //clean off
        if(null != outputStream) {
            try { outputStream.close(); outputStream = null; }
            catch(Exception ex) { }
        }

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:30:09+00:00Added an answer on May 27, 2026 at 8:30 am

    Try to use mimeMessage.setFrom(...) instead of mimeMessage.setSender(...).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET 2.0 (C#) webpage with a link that pulls a blob
Lets say that you have either URL or a link on a webpage that
I have created some code that emails an html email to a given address.
Let's say that I have a link to a webpage that contains some text.
I have a webpage that uses sprites for its navigation link. In IE7 sometimes
I have the following line of code in a link on my webpage: <a
I have link that calls a function when clicked: <a href=javascript:spawnMenu(this); id=link1>Test1</a> To make
I have a link that I dynamically create which looks something like the following:
I have a link in a pdf-document (PDF1), which is embedded in a browser
I have a link on a page that pops up a new window, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.