Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
App. WinForms / WPF .NET
Problema invio mail con outlook in c#
martedì 17 ottobre 2006 - 14.56
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
v.mauri82
Profilo
| Newbie
3
messaggi | Data Invio:
mar 17 ott 2006 - 14:56
Buongiorno a tutti,
ho un problema ad inviare mail con outlook. Ho preso da internet la seguente classe:
public class OutlookMail
{
private Outlook.Application oApp;
private Outlook._NameSpace oNameSpace;
private Outlook.MAPIFolder oOutboxFolder;
/// <summary>
/// Constructor
/// </summary>
public OutlookMail()
{
//Return a reference to the MAPI layer
oApp = new Outlook.Application();
oNameSpace= oApp.GetNamespace("MAPI");
oNameSpace.Logon(null,null,false,false);
//gets defaultfolder for my Outlook Outbox
oOutboxFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
}
/// <summary>
/// Adds an email to MS Outlook Outbox
/// </summary>
/// <param name="toValue">Email address of recipient</param>
/// <param name="subjectValue">Email subject</param>
/// <param name="bodyValue">Email body</param>
public void addToOutBox(string toValue, string subjectValue, string bodyValue, string AtachValue)
{
//creates a new MailItem object
Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMailItem.To = toValue;
oMailItem.Subject = subjectValue;
oMailItem.Body = bodyValue + Environment.NewLine + szFirma;
string sDisplayName = "MyFirstAttachment";
int iPosition = (int)oMailItem.Body.Length + 1;
int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
Outlook.Attachment oAttach = oMailItem.Attachments.Add(AtachValue,iAttachType,iPosition,sDisplayName);
oMailItem.SaveSentMessageFolder = oOutboxFolder;
//uncomment this to also save this in your draft
//oMailItem.Save();
//adds it to the outbox
oMailItem.Send();
oAttach = null;
oMailItem = null;
oApp = null;
}
}
Il tutto funziona correttamente ma il problema è che in Outlook ho due account e la funzione usa quello predefinito per inviare le mail. Come faccio a specificare con quale account spedire?
P.S.: sto usando l'outlook 2000 senza service pack installati
Torna su
Stanze Forum
Elenco Threads
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?
Dopo esserti registrato potrai chiedere
aiuto sul nostro
Forum
oppure aiutare gli altri
Consulta le
Stanze
disponibili.
Registrati ora !